package com.collabscm.waf.app.web;

import org.apache.struts2.dispatcher.ServletDispatcherResult;

import com.collabscm.waf.solution.logging.Logger;
import com.collabscm.waf.solution.logging.LoggerFactory;
import com.collabscm.waf.util.I18nUtils;
import com.opensymphony.xwork2.ActionInvocation;

/**
 * 国际化页面跳转
 * @author Zeng Raoxing
 */
public class I18nDispatcherResult extends ServletDispatcherResult {
	private static final long serialVersionUID = 1L;
	private static final Logger logger = LoggerFactory.getLogger(I18nDispatcherResult.class);

    public I18nDispatcherResult() {
        super();
    }

    public I18nDispatcherResult(String location) {
        super(location);
    }
    
    /**
     * 在跳转前添加前缀，以便能正确的分发到不同语言下
     */
    @Override
    protected String conditionalParse(String param, ActionInvocation invocation) {
    	String location = super.conditionalParse(param, invocation);
    	StringBuffer sb = new StringBuffer("/").append(I18nUtils.getCurrentLanguage());
    	if(!location.startsWith("/")) {
    		sb.append("/");
    	}
    	sb.append(location);
    	return sb.toString();
    }

    @Override
    public void doExecute(String finalLocation, ActionInvocation invocation) throws Exception {
    	logger.debug("当前Forward：{}", finalLocation);
    	super.doExecute(finalLocation, invocation);
    }
    
}
